package co.baiku.boot.handle;

import co.baiku.boot.common.spring.SpringContext;
import co.baiku.boot.common.validate.Validation;
import co.baiku.boot.config.WeixinPayConfig;
import co.baiku.boot.response.item.WeixinRefundNoticeRecord;

import java.math.BigDecimal;
import java.util.Map;

public interface WeixinRefundHandle<T> {

    /**
     * 接到回调信息
     *
     * @param params
     * @throws Exception
     */
    void onMessage(Map<String, String> params) throws Exception;

    /**
     * 获取订单
     *
     * @param out_trade_no
     * @return
     */
    T getByOutTradeNo(String out_trade_no);

    /**
     * 校验订单金额
     *
     * @param t
     * @param total_amount
     * @return
     */
    boolean checkOrderByAmount(T t, BigDecimal total_amount);

    /**
     * 微信退款通知业务逻辑
     *
     * @param t
     * @param weixinRefundNoticeRecord
     */
    void refundBusiness(T t, WeixinRefundNoticeRecord weixinRefundNoticeRecord);

    default WeixinPayConfig weixinPayConfig() {
        WeixinPayConfig weixinPayConfig = SpringContext.getIfPresent(WeixinPayConfig.class);
        if (weixinPayConfig != null) {
            return weixinPayConfig;
        }
        throw Validation.error("未找到合适的WeixinPayConfig,请检查配置信息");
    }
}
